import axios from 'axios'
import { Message } from 'element-ui'
const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API
})
service.interceptors.request.use()
service.interceptors.response.use(
  response => {
    // axios 默认加了一个data
    const { success, message, data } = response.data
    if (success) {
      return data
    } else {
      // 业务错误，进入catch
      Message.error(message) // 提示错误消息
      return Promise.reject(new Error(message))
    }
  }, error => {
    Message.error(error.message)
    return Promise.reject(error) //返回执行错误，进入catch
  }
)
export default service
